public class Solution303 {

    int[] sum;

    public Solution303(int[] nums) {
        sum=new int[nums.length+1];
        for (int i=0;i<nums.length;i++){
            sum[i+1]=sum[i]+nums[i];
        }
    }

    public int sumRange(int left, int right) {
        return sum[right+1]-sum[left];
    }

    public static void main(String[] args) {
        Solution303 solution303=new Solution303(new int[]{-2, 0, 3, -5, 2, -1});
        System.out.println(solution303.sumRange(0,2));
        System.out.println(solution303.sumRange(2,5));
        System.out.println(solution303.sumRange(0,5));
    }
}
